package com.kg.fiber.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ivan.toolkit.common.Aniout;
import com.ivan.toolkit.common.RunningInfo;
import com.kg.fiber.domain.AppConfig;
import com.kg.fiber.service.Boss;

@Controller
@RequestMapping("/boss")
@ResponseBody
public class BossController {
	
	@Autowired
	private Boss boss;
	
	@RequestMapping(value = "/testWarning.do")
	public Aniout testWarning() {
			
		boss.postWarning(true);
		
		return Aniout.success();
		
	}
	
	@RequestMapping(value = "/getConfig.do")
	public AppConfig getConfig() {
		return AppConfig.instance.get();
	}
	
	@RequestMapping(value = "/setConfig.do")
	public Aniout setConfig(AppConfig config) {
		try {
			AppConfig.instance.set(config);
			return Aniout.success();
		} catch (Exception e) {
			return Aniout.failure().message("Exception: " + e.getMessage());
		}
	}
	
	@RequestMapping(value = "/runtime.do")
	public Aniout runtime() {
		
		return Aniout.success().data(RunningInfo.build());
		
	}

}
